#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n,m,ans,a[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> n;
    for(int i = 1;i <= n;++i){
        cin >> m;
        for(int j = 1;j <= m;++j){
            cin >> a[j];
        }
        for(int j = m;j >= 0;--j){
            for(int k = j - 1;k >= 0;--k){
                if(a[j] == a[k]) ans += a[j];
            }
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}
